package com.jh.browser.dao;

import android.content.ContentValues;
import android.database.Cursor;

import com.jh.browser.application.MyApplication;
import com.jh.browser.bean.SearchHistoryBean;
import com.jh.browser.db.SearchHistoryDb;

public class SearchHistoryDao extends MyBaseDao {
    private final String table = "searchhistory";

    /**
     * 添加
     *
     * @param search
     * @return
     */
    public long add(String search) {
        ContentValues values = new ContentValues();
        values.put("search", search);
        long id = writableDatabase.insert(table, null, values);
        return id;
    }

    /**
     * 查询某一个是否存在
     *
     * @param search
     * @return
     */
    public boolean findOne(String search) {
        Cursor cursor = readableDatabase.query(table, new String[]{"_id"}, "search=?", new String[]{search}, null, null, null);
        if (cursor.moveToNext()) {
            return true;
        }
        cursor.close();
        return false;
    }


    @Override
    public SearchHistoryDb getDb() {
        return new SearchHistoryDb(MyApplication.getContext(), table, null, 1);
    }

    @Override
    public Class getClazz() {
        return SearchHistoryBean.class;
    }

    @Override
    public String getTableName() {
        return table;
    }
}
